#include <iostream>
#include <queue>
#include <functional>
using namespace std;

typedef priority_queue <int, deque<int>, greater<int> > PQ;

int draws;
PQ losses;


int calculate_points (int g, int points)
{
	int p, d, gn;

	p = min (g, draws);
	points += p * 2;
	g -= p;

	while (g && !losses.empty())
	{
		d = losses.top(); losses.pop();
		if (g > d)
		{
			points += 3;
			g -= d + 1;
		}
		else if (g == d)
		{
			points += 1;
			g -= d;
		}
	}

	return points;
}


int main ()
{
	int n, g, s, r, d, points;

	while (cin >> n >> g, !cin.fail())
	{
		points = 0;
		draws = 0;
		while (!losses.empty())
			losses.pop();
		while (n--)
		{
			cin >> s >> r;
			d = s - r;
			if (d > 0)
			{
				points += 3;
			}
			else if (d == 0)
			{
				points += 1;
				++draws;
			}
			else
			{
				losses.push (-d);
			}
		}
		cout << calculate_points (g, points) << endl;
	}

	return 0;
}